package com.voxel.sense.infomsg.module.task.execution.report.list;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;
import com.voxel.sense.infomsg.interfaces.listener.AddItemPortionClickListener;

import butterknife.BindView;
import cyy.example.com.facotry.model.api.response.TaskReportListEntity;

/**
 * @author ChenYiYao
 * @date 2018/5/14
 * des :
 */
public class ReportListAdapter extends RecyclerAdapter<TaskReportListEntity> {
    private AddItemPortionClickListener mDeleteClickListener;


    @Override
    protected int getItemViewType(int position, TaskReportListEntity taskReportListEntity) {
        return R.layout.item_recycler_layout_report_list;
    }


    @Override
    protected ViewHolder<TaskReportListEntity> onCreateViewHolder(View root, int viewType) {
        return new VHolder(root);
    }

    @Override
    public void onBindViewHolder(ViewHolder<TaskReportListEntity> holder, int position) {
        super.onBindViewHolder(holder, position);
        View delete = holder.itemView.findViewById(R.id.iv_delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDeleteClickListener != null) {
                    mDeleteClickListener.onItemChildViewClick(delete, position, mDataList.get(position));
                }
            }
        });
    }


    public void setDeleteClickListener(AddItemPortionClickListener deleteClickListener) {
        mDeleteClickListener = deleteClickListener;
    }

    public static class VHolder extends ViewHolder<TaskReportListEntity> {
        @BindView(R.id.tv_desc)
        TextView tv_desc;
        @BindView(R.id.iv_delete)
        ImageView iv_delete;

        public VHolder(View itemView) {
            super(itemView);
        }

        @Override
        protected void onBind(TaskReportListEntity entity) {
            tv_desc.setText(entity.getFormName());
            if (entity.getParam2().equals(true + "")) {
                iv_delete.setVisibility(View.VISIBLE);
            } else {
                iv_delete.setVisibility(View.GONE);

            }
        }
    }

}
